#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>


int main()
{
    char ch;
    //打开控制终端
    int tty = open("/dev/tty", O_RDONLY);
    struct termios newt, oldt;
    //获取终端属性
    tcgetattr(tty, &oldt);
    newt = oldt;
    //设置字符不缓冲且不回显
    newt.c_lflag &= ~( ICANON | ECHO );
    tcsetattr(tty, TCSANOW, &newt);
    while (1) {
        read(tty, &ch, 1);
        if (ch == 0x03) {
            //还原终端属性
            tcsetattr(tty, TCSANOW, &oldt);
            fprintf(stderr, "Quit\n", ch);
            break;
        } else {
            fprintf(stderr, "[%c]\n", ch);
        }
    }
    return 0;
}
